#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/i2c.h>
#include <linux/err.h>
#include <linux/regmap.h>
#include <linux/slab.h>

/* 可以匹配多个i2c设备生成1个dev */
static const unsigned short normal_i2c[] = { 0x50, 0x55, I2C_CLIENT_END };

static struct i2c_client *at24c02_client;

static int at24c02_dev_init(void)
{
	struct i2c_adapter *i2c_adap;
    struct i2c_board_info i2c_info;

    /* register I2C device */
    /* 获取i2c总线, 根据i2c设备挂在哪个adapter下 */
	i2c_adap = i2c_get_adapter(0);
    /* 和id_table进行匹配的名字 */
    memset(&i2c_info, 0, sizeof(struct i2c_board_info));
    strlcpy(i2c_info.type, "at24c02", I2C_NAME_SIZE);
    /* 往获取的i2c总线上new新设备 */
	at24c02_client = i2c_new_probed_device(i2c_adap, &i2c_info, normal_i2c, NULL);
    /* 释放i2c总线 */
	i2c_put_adapter(i2c_adap);
	
	return 0;
}

static void at24c02_dev_exit(void)
{
    /* 释放i2c上new的设备 */
	i2c_unregister_device(at24c02_client);
}


module_init(at24c02_dev_init);
module_exit(at24c02_dev_exit);

MODULE_AUTHOR("huang");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("jz2440 at24c02 client driver");




